package com.iter.devbox.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 研磨JUC API
 * @author Jimly
 *
 */
public class MyCallable implements Callable<Integer> {

	@Override
	public Integer call() throws Exception {
		int ret = 0;
		for (int i=0; i<10; i++) {
			ret += i;
		}
		return ret;
	}
	
	public static void main(String[] args) throws Throwable {
		//创建一个单一的线程池
		ExecutorService poll = Executors.newSingleThreadExecutor();
		//提交任务执行并返回结果
		Future<Integer> future = poll.submit(new MyCallable());
		//打印返回的结果
		System.out.println(future.get());
		//看看线程任务释放已经执行完毕
		System.out.println(future.isDone());
		//关闭线程池
		poll.shutdown();
	}
}
